#include<iostream>
#include<iterator>
#include<algorithm>
using namespace std;

void BubbleSort(int* array, int size)
{
    int i = size - 1;
    
    while (i > 0)
    {
        int lastChange = 0;
        
        for (int j = 0; j < i; j++)
        {
            if (array[j] > array[j + 1])
            {
                int temp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = temp;
                
                lastChange = j;
            }
        }
        
        i = lastChange;
    }
}

int main(void)
{
    int array[] = {52, 49, 80, 36, 14, 58, 61, 23, 97, 75};
    int size = sizeof(array) / sizeof(array[0]);
    
    BubbleSort(array, size);
    
    copy(array, array + size, ostream_iterator<int>(cout, " "));
    
    system("pause");
}
